package linearlist;

import org.junit.Test;

/**
 * @author zhm
 * @date 2020/9/10
 */
public class MySinglyLinkedListTests {

    /**
     * ["MyLinkedList","addAtHead","addAtHead","addAtHead","addAtIndex","deleteAtIndex","addAtHead","addAtTail","get","addAtHead","addAtIndex","addAtHead"]
     * [[],[7],[2],[1],[3,0],[2],[6],[4],[4],[4],[5,0],[6]]
     */

    @Test
    public void test1(){
        MySinglyLinkedList myLinkedList = new MySinglyLinkedList();

        myLinkedList.addAtHead(7);
        myLinkedList.addAtHead(2);
        myLinkedList.addAtHead(1);
        myLinkedList.addAtIndex(3,0);
        myLinkedList.deleteAtIndex(2);
        myLinkedList.addAtHead(6);
        myLinkedList.addAtTail(4);
        myLinkedList.get(4);
        myLinkedList.addAtHead(4);
        myLinkedList.addAtIndex(5,0);
        myLinkedList.addAtHead(6);
        myLinkedList.printAll();
    }

    /**
     *
     ["MyLinkedList","addAtHead","addAtTail","addAtIndex","get","deleteAtIndex","get"]
     [[],[1],[3],[1,2],[1],[0],[0]]
     */
    @Test
    public void test2(){
        MySinglyLinkedList myLinkedList = new MySinglyLinkedList();
        myLinkedList.addAtHead(1);
        myLinkedList.addAtTail(3);
        myLinkedList.addAtIndex(1,2);
        myLinkedList.get(1);
        myLinkedList.deleteAtIndex(0);
        myLinkedList.get(0);
        myLinkedList.printAll();
    }

    @Test
    public void test3(){
        MySinglyLinkedList myLinkedList = new MySinglyLinkedList();
        myLinkedList.addAtIndex(-1,5);
        myLinkedList.addAtIndex(6,2);
        myLinkedList.addAtIndex(0,5);
        myLinkedList.addAtIndex(0,9);
        myLinkedList.addAtIndex(2,8);
        myLinkedList.addAtIndex(1,6);
        myLinkedList.addAtIndex(1,7);
        myLinkedList.addAtIndex(5,3);
        myLinkedList.printAll();


        for (int i = 0; i < 9; i++) {
            System.out.print(myLinkedList.get(i)+"  ");
        }

        System.out.println();
        myLinkedList.deleteAtIndex(0);
        myLinkedList.printAll();
        myLinkedList.deleteAtIndex(4);
        myLinkedList.printAll();
        myLinkedList.deleteAtIndex(1);
        myLinkedList.printAll();
        myLinkedList.deleteAtIndex(9);
        myLinkedList.printAll();
        myLinkedList.deleteAtIndex(3);
        myLinkedList.printAll();
    }

    @Test
    public void test4(){

        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode4 = new ListNode(2);
        ListNode listNode3 = new ListNode(3);
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;



        ListNodeOperation listNodeReverse = new ListNodeOperation();
//        ListNode reverseList1 = listNodeReverse.reverseList(null);
//        ListNode reverseList2 = listNodeReverse.reverseList(listNode1);
//        System.out.println(reverseList2);

        ListNode listNode = listNodeReverse.removeElements(listNode1, 2);
        System.out.println(listNode);
    }

    @Test
    public void test5(){
        ListNodeOperation listNodeReverse = new ListNodeOperation();
        ListNode listNode1 = new ListNode(1);
        listNode1.next = new ListNode(2);
        boolean b = listNodeReverse.hasCycle(listNode1);
        System.out.println(b);
    }

    @Test
    public void test6(){
        ListNodeOperation listNodeOperation = new ListNodeOperation();
        ListNode listNode1 = new ListNode(1);
        listNode1.next = new ListNode(2);
        ListNode listNode = listNodeOperation.detectCycle2(listNode1);
        System.out.println(listNode);
    }

    @Test
    public void test7(){
        ListNode listNode = new ListNode(1);
        listNode.next = listNode;
        ListNode listNode2 = new ListNode(2);
        listNode.next = listNode2;

        while (listNode.next!=null){

            System.out.println(listNode.val);
        }

    }

    @Test
    public void test8(){

        System.out.println(10 >> 1);
        System.out.println(9 >> 1);
    }
}
